﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=utf-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>发卡登记单位</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="${pageContext.request.contextPath }/scripts/boot.js" type="text/javascript"></script>
<style type="text/css">
    html, body
    {
        font-size:12px;
        padding:0;
        margin:0;
        border:0;
        height:100%;
    } 
</style>
</head>
<body>
	  
		    <form id="form1" method="post">
		    <div style="padding-bottom:5px;padding-top:6px;">
		      <table style="table-layout:fixed;width:20%;">
			        <tr>
			          <td style="width:20%;white-space:nowrap;text-align:right;">劳动保障证号：</td>
			          <td style="width:30%;"><input id = "aab001" name="aab001" class="mini-textbox" required="true" emptyText="请输入劳动保障证号" vtype="int;minLength:8" maxlength="8" style="width:100%;" onenter="check()"/></td>
			        </tr>
			        <tr>
			        	<input id = "eventId" name="eventId" class="mini-textbox"  style="width:100%;" visible="false"/>
			        </tr>
		      </table>
		    </div>
		    <fieldset style="border:solid 1px #aaa;padding:3px;">
		      <legend >单位发放</legend>
			  <div id="datagrid1" class="mini-datagrid" style="width:100%;height:370px;" allowResize="true"
			       url="${pageContext.request.contextPath}/DWfk.do?method=getDWfk" idField="id" multiSelect="true" onrowdblclick="onRowDblClick">
				    <div property="columns">
				      <div type="checkcolumn" width="50">发放确认</div> 
				      <div field="c1" width="120" headerAlign="center" >制卡批次
				      	<input property="editor" class="mini-textbox" onenter="onKeyEnter" style="width:100%;"/>
				      </div>
				      <div field="c3" width="120" headerAlign="center" >制卡数量</div>
				      <div field="c4" width="120" headerAlign="center" >起始盒号</div>
				      <div field="c5" width="120" headerAlign="center" >截止盒号</div>
				      <div field="c2" width="120" headerAlign="center" >打印时间</div>
				    </div>
			  </div>
		    </fieldset>
	  </form>
	  <div style="text-align:center;padding:10px;">
	    <a class="mini-button" onclick="onOk"  iconCls="icon-ok" id="onoks" enabled="false" style="width:100px;margin-right:20px;">确认</a>
	    <a class="mini-button" onclick="onCancel"  iconCls="icon-remove" style="width:100px;margin-right:20px;">重置</a>
	  </div>
<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");
    var grid = mini.get("datagrid1");
    
    //校验发卡登记数据
    function check(){
	    var aab001 = mini.getbyName("aab001").getValue().trim();
	    if(aab001 == ""){
			mini.alert("请输入要领卡的单位！");	  
			return;  
	    } else {
	    	if(form.isValid()==true){
	      	    mini.mask({el: document.body,cls: 'mini-mask-loading',html: '查询中...'});
	      	    } 
    	$.ajax({
                url: "${pageContext.request.contextPath}/DWfk.do?method=checkDWfk&id="+aab001,
	            cache: false,  
                success: function (text) {
                	 mini.unmask();
	                var o = mini.decode(text);
	               	 mini.getbyName("eventId").setValue(o.eventid);
	              			search();	              
	              },
	            error: function (jqXHR, textStatus, errorThrown) {
	                alert(jqXHR.responseText);
	                CloseWindow();
	            }
         });
	    }
    }
    //查询单位发卡数据
    function search(){
    	var eventId = mini.getbyName("eventId").getValue().trim();
    	 if (eventId == "") {
	         mini.alert("此单位无待发卡记录！");  
	         return;
	      } else {
	      $.ajax({
	                url: "${pageContext.request.contextPath}/DWfk.do?method=getDWfk1&eventId=" + eventId,
	                cache: false,
	                success: function (text) {
	                	if(text == null || text=="null"){
	                		mini.alert("此单位无待发卡记录！");
	                	}else{
	                		  grid.load({ eventId: eventId});
	                		  mini.get("onoks").setEnabled(true); 
	                	}
	                }
                });
	      }
    	
    }
    
    function onKeyEnter(){
    		
			var onKeyEnter = this;
			var aab001 = mini.getbyName("aab001").getValue().trim();
			
            mini.open({
                url: bootPATH + "../page/sbk_fkdjgl/sbk_zcfkdjgl/sbk_fkdjdw1.jsp",
                title: "发卡明细",
                width: 1000,
                height: 500,
                onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "search", aaz001:row.c1,aaz002:row.c2,aab001:aab001};
                        iframe.contentWindow.SetData(data);
                },
            });    
    }
    function onRowDblClick(e) {
	        onKeyEnter();
	    }
    
    function onOk(){
		savaData();
    }
    
    function onCancel(){
    	form.clear();
        grid.clearRows();
    }
    
    function savaData(){
     	var row = grid.getSelected();
     	if(row){
     		var aab001 = mini.getbyName("aab001").getValue().trim();
			var o = form.getData();
            form.validate();
            if (form.isValid() == false) {
            	return;
            	} else {
           var json = mini.encode([o]);
           $.ajax({
                  url : "${pageContext.request.contextPath}/DWfk.do?method=saveDWfk",
                  type: 'post',
                  data: { data: json,aab001:aab001},
                  cache: false,
                  success: function (text) {
                  	alert(text);
                  	form.clear();
                  },
                  error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    CloseWindow();
                  }
              });
            	}
     	}else{
     		alert("请选中一条记录");
     	}
    }
	    
</script>
</body>
</html>
